var right_addr = true;
var right_email = true;
var right_phone = true;
var right_name = true;
window.onload = init;
function init()
{
document.getElementById("memberEmail").onblur = chkEmail;
document.getElementById("memberPhone").onblur = chkPhone;
document.getElementById("memberName").onblur = chkName;
document.getElementById("memberAddr").onblur = chkAddr;
document.getElementById("register").onsubmit = check;
}
///////////////////帐号///////////////////////
/////////////////////密码///////////////////////
/////////////////////电子邮件///////////////////////
function chkEmail()
{
   var temp = document.getElementById("memberEmail");
   //对电子邮件的验证
   var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
   if(!myreg.test(temp.value))
 {
        //alert('请输入有效邮箱！');
    document.getElementById("emailcheck").src="images/error.jpg";
    document.getElementById("emailcheck").style.display="";
	document.getElementById("email_check_label").innerHTML = "请输入有效邮箱！";
        //temp.focus();
    right_email= false;
  }
else
{
    document.getElementById("emailcheck").src="images/right.jpg";
    document.getElementById("emailcheck").style.display="";
	document.getElementById("email_check_label").innerHTML = "";
    right_email = true;
}

} 
/////////////////////电话///////////////////////////
function chkPhone()
{
   var phone = document.getElementById("memberPhone");
   var str = phone.value;
   var myphone= /^((?:\d{11})|(?:\d{4}-\d{7})|(?:\d{4}-\d{8}))$/;
   if(!myphone.test(str))
   {
    //alert("输入有效电话");
    document.getElementById("phonecheck").src="images/error.jpg";
    document.getElementById("phonecheck").style.display="";
    document.getElementById("phone_check_label").innerHTML = "输入有效电话";
    right_phone = false;
    }
    else
   {
    document.getElementById("phonecheck").src="images/right.jpg";
    document.getElementById("phonecheck").style.display="";
    document.getElementById("phone_check_label").innerHTML = "";
    right_phone = true;
    }
}
/////////////////////名字///////////////////////
function chkName(){
var name = document.getElementById("memberName");
var str  = name.value;  
str = str.replace(/\s+/g,""); 
if(str=="")   
{
   
    document.getElementById("namecheck").src="images/error.jpg";
    document.getElementById("namecheck").style.display="";
    document.getElementById("name_check_label").innerHTML = "请输入名字"; 
    right_name = false; return ;
                               
}
  var ts;      
  var tscode;      
  for (i=0;i<str.length;i++) {      
		      ts=str.substring(i);      
		      tscode=ts.charCodeAt();      
        if ((tscode<19968)||(tscode>40959)) {      
			         //alert("you must input chinese"); 
                 document.getElementById("namecheck").src="images/error.jpg";
    			 document.getElementById("namecheck").style.display="";
   				 document.getElementById("name_check_label").innerHTML = "请输入汉字";    
				 right_Name = false;
	             return;      
           }      
    } 
    document.getElementById("namecheck").src="images/right.jpg";
    document.getElementById("namecheck").style.display="";
    document.getElementById("name_check_label").innerHTML = ""; 
    right_Name = true; 
}
function chkAddr()
{
 var addr = document.getElementById("memberAddr").value;
 if(addr =="")
 { 
 right_addr = true;
 }
 else
 {
 document.getElementById("addrcheck").src="images/right.jpg";
    document.getElementById("addrcheck").style.display="";
    document.getElementById("addr_check_label").innerHTML = ""; 
     right_addr = true;
    
  }
}
 ////////////////////////////////////////////   
function check()
{
    if( right_email == false||right_phone == false||right_name == false||right_addr == false) 
        return false;
        else 
        return true;

}



 
